package sk.tramtatiri;

import org.apache.wicket.Component;
import org.apache.wicket.Page;
import org.apache.wicket.RestartResponseAtInterceptPageException;
import org.apache.wicket.authorization.Action;
import org.apache.wicket.authorization.IAuthorizationStrategy;

import sk.tramtatiri.pages.users.LoginPage;
import sk.tramtatiri.pages.users.SecuredPage;
import sk.tramtatiri.pages.users.UserHomePage;

public class AuthStrategy implements IAuthorizationStrategy {

	public boolean isActionAuthorized(Component component, Action action) {
		return true;
	}

	public <T extends Component> boolean isInstantiationAuthorized(Class<T> componentClass) {
		if(!Page.class.isAssignableFrom(componentClass)) {
			return true;
		}
		
		if(!SecuredPage.class.isAssignableFrom(componentClass)) {
			return true;
		}
		
//		if(LoginPage.class.isAssignableFrom(componentClass)) {
//			return true;
//		}
		
		if(MySession.get().getUserID()==null) {
			throw new RestartResponseAtInterceptPageException(LoginPage.class);
		}
		return true;
	}

}
